package 多线程和队列.锁;

import java.util.concurrent.TimeUnit;

/**
 * @author 孔令富  2021/12/25
 */
public class InterruptCommonTest implements Runnable {


    @Override
    public void run() {
        while (true) {
            System.out.println("你中断一个试试 ");
            boolean interrupted = Thread.interrupted();
            System.out.println("中断状态" + interrupted);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new InterruptCommonTest());
        thread.setDaemon(true);
        thread.start();
        TimeUnit.SECONDS.sleep(5);
        thread.interrupt();
        System.out.println("是否被中断" + thread.isInterrupted());

    }
}
